package javax.core.common.mongo;

/**
 * sql排序组件
 *
 * @author raos
 * @emil 991207823@qq.com
 * @date 2021/8/30 21:22
 */
public class Order {

    /**
     * 升序还是降序
     */
    private boolean ascending;
    /**
     * 那个字段升序或降序
     */
    private String propertyName;

    /**
     * 有参构造字段升序或降序
     */
    protected Order(String propertyName, boolean ascending) {
        this.propertyName = propertyName;
        this.ascending = ascending;
    }

    /**
     * 字段升序
     *
     * @param propertyName
     * @return Order
     */
    public static Order asc(String propertyName) {
        return new Order(propertyName, true);
    }

    /**
     * 字段降序
     *
     * @param propertyName
     * @return Order
     */
    public static Order desc(String propertyName) {
        return new Order(propertyName, false);
    }

    @Override
    public String toString() {
        return propertyName + ' ' + (ascending ? "asc" : "desc");
    }

}
